package com.xrh.tank;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.ImageIcon;

/**
 * @author 肖荣辉
 * @function 血块类,提供给坦克加血的类 (提供一盘包子)
 * @date 2014-3-4
 */
public class Blood {
	int x,y,w,h;
	TankClient tc;
	int step=0;
	private boolean live=true;
	ImageIcon booldPic=new ImageIcon(getClass().getResource("images/baozi.png"));
	
	public boolean isLive() {
		return live;
	}

	public void setLive(boolean live) {
		this.live = live;
	}

	/**
	 * 让血块上下移动,看起来在飘,有动感
	 */
	private int[][] pos={
			{480,250},{480,249},{480,248},{480,247},{480,246},{480,245},{480,246},{480,247},{480,248},{480,249},{480,250}
	};
	/**
	 * 血块的构造方法
	 */
	public Blood(){
		x=pos[0][0];
		y=pos[0][1];
		w=h=15;//设置血块的宽高
	}
	
	/**
	 * 画出血块
	 * @param g 传入画笔对象
	 */
	public void draw(Graphics g){
		if(!live)return ;
		Color c=g.getColor();
		g.setColor(Color.MAGENTA);//品红
		g.drawImage(booldPic.getImage(), x, y, null);
		g.setColor(c);
		move();
	}
	
	private void move(){
		step++;
		if(step==pos.length){
			step=0;
		}
		x=pos[step][0];
		y=pos[step][1];
	}
	
	/**
	 * @return 返回血块的矩形
	 */
	public Rectangle getRect(){
		return new Rectangle(x,y,w,h);
	}
}
